From: Shane King Date: Wed, 24 Nov 2004 12:55:48 +0000 (+0000) Subject: Added the ability to protect a page from moves but not from edits. See X-Git-Tag: 1.5.0alpha1~1251 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=23a94cea16f2e011702061de5ce7dc62b270ddbb;p=lhc%2Fweb%2Fwiklou.git Added the ability to protect a page from moves but not from edits. See bug #868. --- diff --git a/includes/Article.php b/includes/Article.php index b361976008..55622944c3 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -407,8 +407,7 @@ class Article { $this->mCounter = $s->cur_counter; $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp); $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched); - $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) ); - $this->mTitle->mRestrictionsLoaded = true; + $this->mTitle->loadRestrictions( $s->cur_restrictions ); } else { # oldid set, retrieve historical version $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), $fname, $this->getSelectOptions() ); @@ -486,8 +485,7 @@ class Article { $this->mCounter = $s->cur_counter; $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp); $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched); - $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) ); - $this->mTitle->mRestrictionsLoaded = true; + $this->mTitle->loadRestrictions( $s->cur_restrictions ); } else { # oldid set, retrieve historical version $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), $fname, $this->getSelectOptions() ); @@ -1275,14 +1273,20 @@ class Article { } $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted(); + $moveonly = $wgRequest->getBool( 'wpMoveOnly' ); $reason = $wgRequest->getText( 'wpReasonProtect' ); if ( $confirm ) { + $restrictions = "move=" . $limit; + if( !$moveonly ) { + $restrictions .= ":edit=" . $limit; + } + $dbw =& wfGetDB( DB_MASTER ); $dbw->update( 'cur', array( /* SET */ 'cur_touched' => $dbw->timestamp(), - 'cur_restrictions' => (string)$limit + 'cur_restrictions' => $restrictions ), array( /* WHERE */ 'cur_id' => $id ), 'Article::protect' @@ -1315,6 +1319,7 @@ class Article { $check = ''; $protcom = ''; + $moveonly = ''; if ( $limit === '' ) { $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) ); @@ -1328,6 +1333,7 @@ class Article { $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) ); $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) ); $check = htmlspecialchars( wfMsg( 'confirmprotect' ) ); + $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) ); $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) ); $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par ); } @@ -1355,7 +1361,19 @@ class Article { - + " ); + if($moveonly != '') { + $wgOut->AddHTML( " + + + + + + + + " ); + } + $wgOut->addHTML( "   diff --git a/includes/EditPage.php b/includes/EditPage.php index 0188851f16..e6e0ba7c23 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -305,7 +305,7 @@ class EditPage { } else if ( $isCssJsSubpage and 'preview' != $formtype) { $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' )); } - if( $this->mTitle->isProtected() ) { + if( $this->mTitle->isProtected('edit') ) { $wgOut->addHTML( '' . wfMsg( 'protectedpagewarning' ) . "
\n" ); } diff --git a/includes/Skin.php b/includes/Skin.php index 53094d7e07..f0bb25b726 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1060,7 +1060,7 @@ class Skin { function moveThisPage() { global $wgTitle, $wgContLang; - if ( $wgTitle->userCanEdit() ) { + if ( $wgTitle->userCanMove() ) { $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ), wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() ); } // no message if page is protected - would be redundant diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 7b286dcd06..63b0c5d09e 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -224,7 +224,7 @@ class SkinTemplate extends Skin { $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) ); $tpl->set( "exists", $wgTitle->getArticleID() != 0 ); $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" ); - $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" ); + $tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" ); $tpl->set( "helppage", wfMsg('helppage')); */ $tpl->set( 'searchaction', $this->escapeSearchLink() ); @@ -557,7 +557,7 @@ class SkinTemplate extends Skin { ); } if ( $wgUser->getID() != 0 ) { - if ( $wgTitle->userCanEdit()) { + if ( $wgTitle->userCanMove()) { $content_actions['move'] = array( 'class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false, 'text' => wfMsg('move'), diff --git a/includes/Title.php b/includes/Title.php index 2d7f17c090..7f019f7cc8 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -702,13 +702,21 @@ class Title { /** * Does the title correspond to a protected article? + * @param string $what the action the page is protected from, + * by default checks move and edit * @return boolean * @access public */ - function isProtected() { + function isProtected($action = '') { if ( -1 == $this->mNamespace ) { return true; } - $a = $this->getRestrictions(); - if ( in_array( 'sysop', $a ) ) { return true; } + if($action == 'edit' || $action == '') { + $a = $this->getRestrictions("edit"); + if ( in_array( 'sysop', $a ) ) { return true; } + } + if($action == 'move' || $action == '') { + $a = $this->getRestrictions("move"); + if ( in_array( 'sysop', $a ) ) { return true; } + } return false; } @@ -726,12 +734,13 @@ class Title { return $wgUser->isWatched( $this ); } - /** - * Can $wgUser edit this page? + /** + * Is $wgUser perform $action this page? + * @param string $action action that permission needs to be checked for * @return boolean - * @access public - */ - function userCanEdit() { + * @access private + */ + function userCan($action) { $fname = 'Title::userCanEdit'; wfProfileIn( $fname ); @@ -770,7 +779,7 @@ class Title { return false; } - foreach( $this->getRestrictions() as $right ) { + foreach( $this->getRestrictions($action) as $right ) { if( '' != $right && !$wgUser->isAllowed( $right ) ) { wfProfileOut( $fname ); return false; @@ -780,6 +789,24 @@ class Title { return true; } + /** + * Can $wgUser edit this page? + * @return boolean + * @access public + */ + function userCanEdit() { + return $this->userCan('edit'); + } + + /** + * Can $wgUser move this page? + * @return boolean + * @access public + */ + function userCanMove() { + return $this->userCan('move'); + } + /** * Can $wgUser read this page? * @return boolean @@ -854,22 +881,42 @@ class Title { return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ); } + /** + * Loads a string into mRestrictions array + * @param string $res restrictions in string format + * @access public + */ + function loadRestrictions( $res ) { + foreach( explode( ':', trim( $res ) ) as $restrict ) { + $temp = explode( '=', trim( $restrict ) ); + if(count($temp) == 1) { + // old format should be treated as edit/move restriction + $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) ); + $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) ); + } else { + $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) ); + } + } + $this->mRestrictionsLoaded = true; + } + /** * Accessor/initialisation for mRestrictions + * @param string $action action that permission needs to be checked for * @return array the array of groups allowed to edit this article * @access public */ - function getRestrictions() { + function getRestrictions($action) { $id = $this->getArticleID(); if ( 0 == $id ) { return array(); } if ( ! $this->mRestrictionsLoaded ) { $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id ); - $this->mRestrictions = explode( ',', trim( $res ) ); - $this->mRestrictionsLoaded = true; + $this->loadRestrictions( $res ); } - return $this->mRestrictions; + $result = $this->mRestrictions[$action]; + return $result ? $result : array(); } /** diff --git a/languages/Language.php b/languages/Language.php index 2089c1b9a3..5df0d68328 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1199,6 +1199,7 @@ See [[Project:Protected page]] for more information.", 'protectsub' =>"(Protecting \"$1\")", 'confirmprotecttext' => 'Do you really want to protect this page?', 'confirmprotect' => 'Confirm protection', +'protectmoveonly' => 'Protect from moves only', 'protectcomment' => 'Reason for protecting', 'unprotectsub' =>"(Unprotecting \"$1\")", 'confirmunprotecttext' => 'Do you really want to unprotect this page?',